package test.data;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import common.Logger;

import data.exception.DaoException;
import data.mysql.IResultsProcessor;


// Not corresponding to a table.
public class JoinBean implements IResultsProcessor<List<JoinBean>> {

	private Long t1id;

	private Long t2id;

	private Long t1id2;

	private Long t2id2;

	private String t1string;

	private String t2string;
	
	/**
	 * @return the t1id
	 */
	public Long getT1id() {
		return t1id;
	}
	/**
	 * @param t1id the t1id to set
	 */
	public void setT1id(Long t1id) {
		this.t1id = t1id;
	}
	/**
	 * @return the t2id
	 */
	public Long getT2id() {
		return t2id;
	}
	/**
	 * @param t2id the t2id to set
	 */
	public void setT2id(Long t2id) {
		this.t2id = t2id;
	}
	/**
	 * @return the t1id2
	 */
	public Long getT1id2() {
		return t1id2;
	}
	/**
	 * @param t1id2 the t1id2 to set
	 */
	public void setT1id2(Long t1id2) {
		this.t1id2 = t1id2;
	}
	/**
	 * @return the t2id2
	 */
	public Long getT2id2() {
		return t2id2;
	}
	/**
	 * @param t2id2 the t2id2 to set
	 */
	public void setT2id2(Long t2id2) {
		this.t2id2 = t2id2;
	}
	/**
	 * @return the t1string
	 */
	public String getT1string() {
		return t1string;
	}
	/**
	 * @param t1string the t1string to set
	 */
	public void setT1string(String t1string) {
		this.t1string = t1string;
	}
	/**
	 * @return the t2string
	 */
	public String getT2string() {
		return t2string;
	}
	/**
	 * @param t2string the t2string to set
	 */
	public void setT2string(String t2string) {
		this.t2string = t2string;
	}
	
	private static final Logger logger = new Logger(JoinBean.class);
	
	// This can also be set as anonymous function in DAO.
	@Override
	public List<JoinBean> populateResults(ResultSet resultSet, String[] fieldsName)
			throws DaoException {
		
		List<JoinBean> results = new ArrayList<JoinBean>();
		try {
			
			while (resultSet.next()) {
				
				// Add to results
				JoinBean result = new JoinBean();
				for (String field : fieldsName) {
					if ("t1id".equals(field)) {
						result.setT1id(resultSet.getLong(field));
						
					} else if ("t2id".equals(field)) {
						result.setT2id(resultSet.getLong(field));
						
					} else if ("t1id2".equals(field)) {
						result.setT1id2(resultSet.getLong(field));
						
					} else if ("t2id2".equals(field)) {
						result.setT2id2(resultSet.getLong(field));
						
					} else if ("t1string".equals(field)) {
						result.setT1string(resultSet.getString(field));
						
					} else if ("t2string".equals(field)) {
						result.setT2string(resultSet.getString(field));
					}
				}
				results.add(result);
	        }
			
		} catch (SQLException e) {
			String msg = "Failed to populate JoinBean.";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
		return results;
	}
}
